home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / scripts / rcs / Setrcsname < prev    next >
Encoding:
Text File  |  1994-08-02  |  4.7 KB  |  167 lines

  1. #! /bin/csh -f
  2. #
  3. # $Id: Setrcsname,v 1.5 93/12/16 14:48:11 carlson Exp $
  4. #
  5. # Setrcsname    Sets a name for a revision of every RCS file.
  6. #
  7. # Synopsis:
  8. #    Setrcsname -n <name> [-l] [file-list]
  9. #    Setrcsname -n <name>:<rev> [-m] [file-list]
  10. #    Setrcsname -N <name> [-l] [file-list]
  11. #    Setrcsname -N <name>:<rev> [-m] [file-list]
  12. #
  13. # Description:
  14. #    This script sets a symbolic name for a revison of an RCS file.
  15. #
  16. #    In the first form, if the -l is not provided, the symbolic
  17. #    name is deleted (if it exists).  Otherwise, the last revision
  18. #    has the last component removed and is used as the revision.
  19. #    If the symbolic name already exists for another revision, an
  20. #    error is printed by rcs.
  21. #
  22. #    In the second form, the specified revision is given the
  23. #    symbolic name.  If the symbolic name already exists for
  24. #    another revision, an error is printed by rcs.
  25. #
  26. #    The third form is identical to the first form except if the
  27. #    symbolic name already exists for another revision, it is
  28. #    overridden.
  29. #
  30. #    The fourth form is identical to the second form except it the
  31. #    symbolic name already exists for another revision, it is
  32. #    overridden.
  33. #
  34. # Parameters:
  35. #    -n <name>    Symbolic name to define.
  36. #    -N <name>    Symbolic name to define and override if it exists.
  37. #    -l        Use last revision of file to set symbolic name to.
  38. #    -m        Set symbolic name only if revision exists.
  39. #
  40. # Revision History:
  41. #    $Log:    Setrcsname,v $
  42. # Revision 1.5  93/12/16  14:48:11  carlson
  43. # Added the ability to provide an actual file list to perform the function
  44. #   to on the command line.
  45. # Revision 1.4  92/10/27  10:05:50  carlson
  46. # Put checking of options in an if statement that is dependent on whether
  47. #   there are any options.  This allowed the usage statement to be printed
  48. #   if no options or arguments are provided.
  49. # Revision 1.3  92/08/21  16:31:00  carlson
  50. # Added more output to when called with no parameters.
  51. # Revision 1.2  91/07/27  20:07:12  chris
  52. # Completely revamped this script.  Provide all kinds of ways to set
  53. #   a symbolic name to a bunch of RCS files.
  54. #---------------------------------------------------------------------------
  55.  
  56. set name = ""
  57. set last = 0
  58. set override = 0
  59. set modify = 0
  60.  
  61. if ( $#argv >= 1 ) then
  62.     set argv = `getopt lmn:N: $*`
  63.     while ( "$1" != "--" )
  64.         switch ( $1 )
  65.           case "-l":
  66.         set last = 1
  67.         shift
  68.         breaksw
  69.  
  70.           case "-m":
  71.         set modify = 1
  72.         shift
  73.         breaksw
  74.  
  75.           case "-n":
  76.         set name = $2
  77.         shift; shift
  78.         breaksw
  79.  
  80.           case "-N":
  81.         set name = $2
  82.         set override = 1
  83.         shift; shift
  84.         breaksw
  85.         endsw
  86.     end
  87.     shift
  88. endif
  89.  
  90. if ( "$name" == "" ) then
  91.     echo "Usage: Setrcsname -n <name> [-l] [file-list]"
  92.     echo "       Setrcsname -n <name>:<rev> [-m] [file-list]"
  93.     echo "       Setrcsname -N <name> [-l] [file-list]"
  94.     echo "       Setrcsname -N <name>:<rev> [-m] [file-list]"
  95.     echo " -n <name>   Symbolic name to define."
  96.     echo " -N <name>   Symbolic name to define and override if it exists."
  97.     echo " -l          Use last revision of file to set symbolic name to."
  98.     echo " -m          Set symbolic name only if revision exists."
  99.     echo " [file-list] Optional list of files to do."
  100.     exit
  101. endif
  102.  
  103. #----
  104. # rev = revision portion of name provided (everything after :)
  105. # name = name portion (everything before :)
  106. # Revc = revision preceded by colon
  107. #
  108. set rev = `echo $name | awk -F: '{ print $2 }'`
  109. set name = `echo $name | awk -F: '{ print $1 }'`
  110.  
  111. if ( "$rev" != "" ) then
  112.     set last = 0
  113.     set Revc = :$rev
  114. else
  115.     set modify = 0
  116.     set Revc = ""
  117. endif
  118.  
  119. #----
  120. # If no files were provided on the command line,
  121. # loop through each RCS file found.  If there is an RCS directory,
  122. # loop through the files ending in ",v" in it.  Otherwise, loop
  123. # through files in the current directory ending in ",v".
  124. #
  125. set rcsdir = ""
  126. if ( -d RCS ) set rcsdir = "RCS/"
  127.  
  128. if ( $#argv == 0 ) then
  129.     set fileList = `ls ${rcsdir}*,v` 
  130. else
  131.     set fileList = ( $argv )
  132. endif
  133.  
  134. foreach rcsfile ( $fileList )
  135.     set file = `basename $rcsfile ,v`
  136.  
  137.     #----
  138.     # If we are supposed to set the last revision, get the last
  139.     # revision and remove the last component.
  140.     #
  141.     # If we are only to set the symbolic name if the revision exists,
  142.     # check if the revision exists and skip if not there.
  143.     #
  144.     if ( $last ) then
  145.     set rev = `rlog $file | grep "^head:" | awk '{print $NF}'`
  146.     set Rev = `echo $rev | awk -F. '{for(i=1;i<NF-1;i++)printf "%s.",$i;print $i}'`
  147.     set Revc = :$Rev
  148.     else if ( $modify ) then
  149.     set x = `rlog $file | grep "^revision $rev"`
  150.     if ( "$x" == "" ) continue
  151.     endif
  152.  
  153.     if ( $override ) then
  154.     rcs -N${name}${Revc} $file
  155.     else
  156.     rcs -n${name}${Revc} $file
  157.     endif
  158. end
  159.  
  160. ### Local Variables:
  161. ### auto-fill-hook: nil
  162. ### End:
  163.